package com.heima.wemedia.service.impl;

import com.heima.common.contants.ScheduleConstants;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.schedule.dtos.Task;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.schedule.feign.TaskFeign;
import com.heima.utils.common.JsonUtils;
import com.heima.wemedia.service.WmNewsTaskService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class WmNewsTaskServiceImpl implements WmNewsTaskService {
    @Autowired
    private TaskFeign taskFeign;
    @Override
    public void addTaskToList(WmNews wmNews) {
        //封装Task
        Task task = new Task();
        task.setTaskTopic(ScheduleConstants.TASK_TOPIC_NEWS_PUBLISH);
        task.setExecuteTime(wmNews.getPublishTime().getTime());//发布时间

        WmNews news = new WmNews();
        news.setId(wmNews.getId());

        task.setParameters(JsonUtils.toString(news));//任务参数：存放文章的ID

        //远程调用，存入延迟队列
        taskFeign.addTask(task);

        log.info("添加文章定时任务到队列中 {}，id:"+wmNews.getId());
    }
}
